package cn.wen.yaling.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cn.wen.yaling.commons.entity.NoticesEntity;
import cn.wen.yaling.xo.service.NoticesService;
import cn.wen.yaling.commons.utils.PageUtils;
import cn.wen.yaling.commons.utils.ResultEntity;



/**
 * 
 *
 * @author FY
 * @email 932043654@qq.com
 * @date 2022-08-13 02:07:37
 */
@RestController
@RequestMapping("web/notices")
public class NoticesController {
    @Autowired
    private NoticesService noticesService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public ResultEntity list(@RequestParam Map<String, Object> params){
        PageUtils page = noticesService.queryPage(params);

        return ResultEntity.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{noticeId}")
    public ResultEntity info(@PathVariable("noticeId") Integer noticeId){
		NoticesEntity notices = noticesService.getById(noticeId);

        return ResultEntity.ok().put("notices", notices);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public ResultEntity save(@RequestBody NoticesEntity notices){
		noticesService.save(notices);

        return ResultEntity.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public ResultEntity update(@RequestBody NoticesEntity notices){
		noticesService.updateById(notices);

        return ResultEntity.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public ResultEntity delete(@RequestBody Integer[] noticeIds){
		noticesService.removeByIds(Arrays.asList(noticeIds));

        return ResultEntity.ok();
    }

}
